package comum;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
/**
 * Objeto serializavel que representa o arquivo
 */
public class Arquivo implements Serializable{
	
	private static final long serialVersionUID = 1L;
	private byte[] bytes;
	
	public Arquivo(InputStream inputStream) {
		try {
			setBytes(inputStream);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	private void setBytes(InputStream input) throws IOException {
		byte[] conversao = new byte[8192];
		ByteArrayOutputStream output = new ByteArrayOutputStream();

		for (int length = 0; (length = input.read(conversao)) > 0;) {
		    output.write(conversao, 0, length);
		}
		
		bytes = output.toByteArray(); 
	}
	
	public byte[] getBytes() {
		return bytes;
	}

}
